<div class="step">
    <table>
        <tr>
                <td  colspan="4" align="center" valign="middle" class="table-title">
                    BẢNG KÊ KHAI NĂNG LỰC LẦN ĐẦU<br>
                    CỦA TỔ CHỨC TƯ VẤN THIẾT KẾ CÔNG TRÌNH GIAO THÔNG</td>
            </tr>
        <tr>
            <td><a href="javascript:void(0);">Bước 1</a></td>
            <td class="seft" ><a href="javascript:void(0);">Bước 2</a></td>            
            <td><a href="javascript:void(0);">Bước 3</a></td>
            <td><a href="javascript:void(0);">Bước 4</a></td>
        </tr>
    </table>
</div>
<form name=frm id=frm>
        <table width="100%" cellpadding="0" cellspacing="2" class="admintable resize">
            <tr>
                <td colspan="5"><b>PHẦN KÊ KHAI NĂNG LỰC NHÂN SỰ </b></td>
            </tr>
            <tr>
                
                <td class="key" nowrap="nowrap"><label  class="form-label optional">Họ và tên KTS/KS:</label></td>
                <td colspan="3">
				<input type="hidden" name="ID_NLNS" id="ID_NLNS"/>
				<input type="text" name="HOTEN" id="HOTEN"/></td>
            </tr>
            <tr>
               
                <td class="key" nowrap="nowrap"><label  class="form-label optional">Số CMND:</label></td>
                <td ><input type="text" name="CMND" id="CMND"/></td>
                <td  class="key" ></td>
                <td ></td>
            </tr>
			<tr>
               
                <td class="key" nowrap="nowrap"><label  class="form-label optional">Số chứng chỉ hành nghề:</label></td>
                <td ><input type="text" name="SOCHUNGCHIHANHNGHE" id="SOCHUNGCHIHANHNGHE"/></td>
                <td  class="key" ></td>
                <td ></td>
            </tr>
            <tr>
               
                <td class="key" nowrap="nowrap"><label  class="form-label optional">Được hành nghề:</label></td>
                <td colspan="3"><input type="text" name="NGHE" id="NGHE"/></td>
            </tr>
            <tr>
               
                <td class="key" nowrap="nowrap"><label  class="form-label optional">Bảo hiểm xa hội:</label></td>
                <td colspan="3">
					Số <input type="text" name="BAOHIEMXAHOI_SO" id="BAOHIEMXAHOI_SO"/>
					Ngày <input type="text" name="BAOHIEMXAHOI_NGAY" id="BAOHIEMXAHOI_NGAY"/>
					Nơi cấp <input type="text" name="BAOHIEMXAHOI_NOICAP" id="BAOHIEMXAHOI_NOICAP"/>
				</td>
            </tr>
            <tr>
               
                <td class="key" nowrap="nowrap" colspan="1" valign=top>
                    <label  class="form-label optional"><em>Cấp hạng:</em></label>
                </td>
                <td>
					<?php
						foreach($this->level as $itemlevel){
					?>
							<input type="radio" name="ID_LV" value="<?=$itemlevel["ID_LV"]?>" onclick="document.frm.DIEM.value='<?=$itemlevel["DIEM"]?>';"/> <em><?=htmlspecialchars($itemlevel["NAME"])?></em><br>
					<?php
						}
					?>
				</td>
                <td><em>Ghi chú cấp hạng:</em><br><textarea name=GHICHU id=GHICHU></textarea></td>
            </tr>
            <tr>
               
                <td class="key" nowrap="nowrap"><label  class="form-label optional">Điểm nhân sự:</label></td>
                <td colspan="3"><input type="text" name="DIEM" id="DIEM"/></td>
            </tr>
            
            <tr>
				<td></td>
				<td valign="middle">
					<a href="javascript:void(0);" class="yl" onclick="SaveToList();return false;" id=addtolist>Thêm mới</a>
					<a href="javascript:void(0);" class="yl" onclick="Clear();return false;">Huỷ</a>
				</td>
            </tr>
            
            <tr>
                <td colspan="3">
                    <b>DANH SÁCH NĂNG LỰC NHÂN SỰ ĐÃ KÊ KHAI</b>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table width="100%" style="border: 1px solid #999999" cellpadding="0" cellspacing="0" id=NLNSLIST>
                        <tr>
                        <th style="border: 1px solid #999999;" align="center" valign="middle">TT</th>
                        <th style="border: 1px solid #999999;" align="center" valign="middle">Họ và tên KTS/KS</th>
                        <th style="border: 1px solid #999999;" align="center" valign="middle">Số chứng chỉ hành nghề</th>
                        <th style="border: 1px solid #999999;" align="center" valign="middle">Được hành nghề</th>
                        <th style="border: 1px solid #999999;" align="center" valign="middle">Cấp Hạng</th>
                        <th style="border: 1px solid #999999;">Điểm nhân sự</th>
                        <th style="border: 1px solid #999999;">Hành động</th>
                      </tr>
					  <?php
						foreach($this->nlns as $itemnlns){
					  ?>
                      <tr id=NLNS<?=$itemnlns["ID_NLNS"]?>>
                          <td style="border: 1px solid #999999;" id=STT<?=$itemnlns["ID_NLNS"]?>>
							<?php
								if($itemnlns["STATUS"]==0){
									echo $itemnlns["STT"];
								}
								if($itemnlns["STATUS"]==1){
									echo "*";
								}
								if($itemnlns["STATUS"]==2){
									echo "+";
								}
								if($itemnlns["STATUS"]==3){
									echo "-";
								}
							?>
						  </td>
                          <td style="border: 1px solid #999999;">
							<a href="#" onclick="LoadNhanSu(<?=$itemnlns["ID_NLNS"]?>);return false;" id=HOTEN<?=$itemnlns["ID_NLNS"]?>>
								<?=htmlspecialchars($itemnlns["HOTEN"])?>
							</a>
						</td>
                          <td style="text-align: right;border: 1px solid #999999;" id=SOCHUNGCHIHANHNGHE<?=$itemnlns["ID_NLNS"]?>><?=htmlspecialchars($itemnlns["SOCHUNGCHIHANHNGHE"])?></td>
                          <td style="text-align: center;border: 1px solid #999999;" id=NGHE<?=$itemnlns["ID_NLNS"]?>><?=htmlspecialchars($itemnlns["NGHE"])?></td>
                          <td style="text-align: center;border: 1px solid #999999;" id=NAMELEVEL<?=$itemnlns["ID_NLNS"]?>><?=htmlspecialchars($itemnlns["NAMELEVEL"])?></td>
                          <td style="text-align: right;border: 1px solid #999999;" id=DIEM<?=$itemnlns["ID_NLNS"]?>><?=htmlspecialchars($itemnlns["DIEM"])?></td>
						  <td style="text-align: right;border: 1px solid #999999;" id=DELETE<?=$itemnlns["ID_NLNS"]?>><a href="javascript:void(0);" onclick="Delete(<?=$itemnlns["ID_NLNS"]?>);return false;">Xoá</a></td>
                      </tr>
					  <?php
						}
					  ?>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3" align="right" valign="middle">
                    <a href="javascript:void(0);" onclick="loadUrlToDivContent('/default/index/tvtkbuoc1')" class="rd">Trở lại</a>
                    <a href="javascript:void(0);" onclick="loadUrlToDivContent('/default/index/tvtkbuoc3')" class="gr">Tiếp Tục</a>
                        
                </td>
            </tr>
            </table>
</form>
<script>
	function UpdateARow(html){
	
		var data = jQuery.parseJSON( html );

		if(typeof data.msg === 'undefined')
		{
			if(data.IS_NEW==1){
				var trhtml = "";
				trhtml += '<tr id=NLNS'+data.ID_NLNS+' class="nlnsnew">';
				  trhtml += '<td style="border: 1px solid #999999;" id=STT'+data.ID_NLNS+'></td>';
				  trhtml += '<td style="border: 1px solid #999999;">';
					trhtml += '<a href="#" onclick="LoadNhanSu('+data.ID_NLNS+');return false;" id=HOTEN'+data.ID_NLNS+'>';
					trhtml += '</a>';
				trhtml += '</td>';
				  trhtml += '<td style="text-align: right;border: 1px solid #999999;" id=SOCHUNGCHIHANHNGHE'+data.ID_NLNS+'></td>';
				  trhtml += '<td style="text-align: center;border: 1px solid #999999;" id=NGHE'+data.ID_NLNS+'></td>';
				  trhtml += '<td style="text-align: center;border: 1px solid #999999;" id=NAMELEVEL'+data.ID_NLNS+'></td>';
				  trhtml += '<td style="text-align: right;border: 1px solid #999999;" id=DIEM'+data.ID_NLNS+'></td>';
				  trhtml += '<td style="text-align: right;border: 1px solid #999999;" id=DELETE'+data.ID_NLNS+'><a href="#" onclick="Delete('+data.ID_NLNS+');return false;">Xoá</a></td>';
			  trhtml += '</tr>';
			  $tr = $(trhtml);
			  $('#NLNSLIST').append($tr);
			}else if(data.IS_NEW==2){
				$('#NLNS'+data.ID_NLNS).remove();
			}
			
			if(data.IS_NEW != 2){
				$('#NLNS'+data.ID_NLNS).find('#STT'+data.ID_NLNS).html(data.STATUS==1?"*":(data.STATUS==2?"+":"-"));
				$('#NLNS'+data.ID_NLNS).find('#HOTEN'+data.ID_NLNS).html(data.HOTEN);
				$('#NLNS'+data.ID_NLNS).find('#SOCHUNGCHIHANHNGHE'+data.ID_NLNS).html(data.SOCHUNGCHIHANHNGHE);
				$('#NLNS'+data.ID_NLNS).find('#NGHE'+data.ID_NLNS).html(data.NGHE);
				$('#NLNS'+data.ID_NLNS).find('#NAMELEVEL'+data.ID_NLNS).html(data.NAMELEVEL);
				$('#NLNS'+data.ID_NLNS).find('#DIEM'+data.ID_NLNS).html(data.DIEM);
			}
			Clear();
		}else{
			alert(data.msg);
		}
	}

	function Delete(id){
		//tvtkbuoc2savedraft
		$.post( "/default/index/tvtkbuoc2savedraft/delete/"+id)
			.done(function(html) {
				UpdateARow(html);
			})
			.fail(function() {
				
			})
			.always(function() {
				
			});
	}

	function SaveToList(){
	
		//tvtkbuoc2savedraft
		$.post( "/default/index/tvtkbuoc2savedraft", $( "#frm" ).serialize() )
			.done(function(html) {
				UpdateARow(html);
			})
			.fail(function() {
				
			})
			.always(function() {
				
			});
	}

	function LoadNhanSu(id){
		$.ajax({
					url: '/default/index/tvtkbuoc2loadnlns/id/'+id,
					type: 'POST',
					cache: false,
					dataType: 'json',
					success: function(data, textStatus, jqXHR)
					{
						if(typeof data.msg === 'undefined')
						{
							$('#HOTEN').val(data.HOTEN);
							$('#CMND').val(data.CMND);
							$('#NGHE').val(data.NGHE);
							$('#SOCHUNGCHIHANHNGHE').val(data.SOCHUNGCHIHANHNGHE);
							$('#BAOHIEMXAHOI_SO').val(data.BAOHIEMXAHOI_SO);
							$('#BAOHIEMXAHOI_NGAY').val(data.BAOHIEMXAHOI_NGAY_VN);
							$('#BAOHIEMXAHOI_NOICAP').val(data.BAOHIEMXAHOI_NOICAP);
							$('#DIEM').val(data.DIEM);
							$('#GHICHU').val(data.GHICHU);
							$('#ID_NLNS').val(data.ID_NLNS);
							var $radios = $('input:radio[name=ID_LV]');
							$radios.filter('[value='+data.ID_LV+']').prop('checked', true);
							$('#addtolist').html("Cập nhật");
						}
						else
						{
							alert(data.msg);
						}
					},
					error: function(jqXHR, textStatus, errorThrown)
					{

					}
				});
	}

	function Clear(){
		$('#HOTEN').val("");
		$('#CMND').val("");
		$('#NGHE').val("");
		$('#SOCHUNGCHIHANHNGHE').val("");
		$('#BAOHIEMXAHOI_SO').val("");
		$('#BAOHIEMXAHOI_NGAY').val("");
		$('#BAOHIEMXAHOI_NOICAP').val("");
		$('#DIEM').val(0);
		$('#GHICHU').val("");
		$('#ID_NLNS').val(0);
		$('#addtolist').html("Thêm mới");
	}

	$("form :input").change(function() {
		$('#savetemp').show(200);
	});
	$('#savetemp').hide();

	$( "#BAOHIEMXAHOI_NGAY" ).datepicker();
	$( "#BAOHIEMXAHOI_NGAY" ).datepicker("option", "dateFormat", "dd/mm/yy");
</script>
